package de.hska.algo.labor2010.strecken;

import java.util.ArrayList;


import java.util.Random;
/**
 * creates and holds n objects of type  {@link Line}  in an ArrayList, Lines are generated randomly
 * @author  Daniela Brenner
 * @version  1.0
 */
public class RandomLines implements LinesGenerator {
	
	
	private ArrayList<Line> lines;
	/**
	 * create an ArrayList of size n
	 * @param n number of Lines that should be created
	 */
	public RandomLines(int n) {
		lines = new ArrayList<Line>(n);
		create(n);
	}
	
	/**
	 * creates n {@link Line}s with random starting and ending {@link Point}s in a range -500 <= x,y <= 500
	 */
	@Override
	public void create(int n) {
		Random r = new Random();
		
		int rangeMin = 0;
		int rangeMax = 500;
		for (int i = 0; i < n; i++) {
			lines.add(new Line(rangeMin + (rangeMax - rangeMin)
					* r.nextDouble(), rangeMin + (rangeMax - rangeMin)
					* r.nextDouble(), rangeMin + (rangeMax - rangeMin)
					* r.nextDouble(), rangeMin + (rangeMax - rangeMin)
					* r.nextDouble()));
		}
	}
	
	

	/* (non-Javadoc)
	 * @see de.hska.algo.labor2010.strecken.Lines#show()
	 */
	
	public String toString() {
		String sth = "Lines\n";
		int i = 0;
		for (Line line : lines) {
			sth+= i + ": " + line.toString();
			i++;
		}
		return sth;

	}
	public ArrayList<Line> getLines() {
		return lines;
	}

	public void setLines(ArrayList<Line> lines) {
		this.lines = lines;
	}


}
